package com.wz.project.bas.trayCode.controller;

import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.bas.trayCode.domain.TrayCode;
import com.wz.project.bas.trayCode.service.ITrayCodeService;
import com.wz.project.bas.trayCodeHead.domain.BasTraycodeHead;
import com.wz.project.bas.trayCodeHead.service.IBasTraycodeHeadService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 基础托盘条码管理 信息操作处理
 * 
 * @author sys
 * @date 2021-10-28
 */
@Controller
@RequestMapping("/bas/trayCode")
public class TrayCodeController extends BaseController
{
    private String prefix = "bas/trayCode";
	
	@Autowired
	private ITrayCodeService trayCodeService;

	@Autowired
	private IBasTraycodeHeadService basTraycodeHeadService;
	
	@RequiresPermissions("bas:trayCode:view")
	@GetMapping()
	public String trayCode()
	{
	    return prefix + "/trayCode";
	}

	@GetMapping("/trayCodes")
	public String trayCodes() {
		return prefix + "/trayCodes";
	}


	
	/**
	 * 查询基础托盘条码管理列表
	 */
//	@RequiresPermissions("module:trayCode:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TrayCode trayCode)
	{
		startPage();
		List<TrayCode> list = trayCodeService.selectTrayCodeList(trayCode);
		return getDataTable(list);
	}
	
	/**
	 * 新增基础托盘条码管理
	 */
	@GetMapping("/add")
	public String add(ModelMap modelMap)
	{
		BasTraycodeHead basTraycodeHead=new BasTraycodeHead();
		 List<BasTraycodeHead> traycodeHeadList=basTraycodeHeadService.selectBasTraycodeHeadList(basTraycodeHead);
		modelMap.put("traycodeHeadList",traycodeHeadList);
	    return prefix + "/add";
	}

	/**
	 * 新增基础托盘条码管理
	 */
	@GetMapping("/adds")
	public String adds(ModelMap modelMap)
	{
		BasTraycodeHead basTraycodeHead=new BasTraycodeHead();
		List<BasTraycodeHead> traycodeHeadList=basTraycodeHeadService.selectBasTraycodeHeadList(basTraycodeHead);
		modelMap.put("traycodeHeadList",traycodeHeadList);
		return prefix + "/adds";
	}
	
	/**
	 * 新增保存基础托盘条码管理
	 */
	@RequiresPermissions("module:trayCode:add")
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TrayCode trayCode)
	{

		trayCodeService.insertTrayCode(trayCode);
		return AjaxResult.success();

	}

	@RequiresPermissions("module:trayCode:add")
	@PostMapping("/adds")
	@ResponseBody
	public AjaxResult addSaves(TrayCode trayCode)
	{
		TrayCode trayCode1 = trayCodeService.selectTrayCode(trayCode.getTrayCode());
		if (trayCode1!=null){
			return AjaxResult.error("已存在此條碼");
		}
		trayCodeService.insertTrayCodes(trayCode);
		return AjaxResult.success();
	}

	/**
	 * 修改基础托盘条码管理
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		TrayCode trayCode1 = trayCodeService.selectTrayCodeById(id);
		mmap.put("trayCode", trayCode1);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存基础托盘条码管理
	 */
	@RequiresPermissions("module:trayCode:edit")
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TrayCode trayCode)
	{		
		return toAjax(trayCodeService.updateTrayCode(trayCode));
	}
	
	/**
	 * 删除基础托盘条码管理
	 */
	@RequiresPermissions("module:trayCode:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(trayCodeService.deleteTrayCodeByIds(ids));
	}

	@RequestMapping("selectCount")
	@ResponseBody
	public int selectCount(String tHead){
		return trayCodeService.selectHeadCount(tHead);
	}

	@RequestMapping("/updateStatus")
	@ResponseBody
	public int updateStatus(String trayCode){
		trayCodeService.updateStatus(trayCode);
		return 1;
	}
	
}
